//
//  commentsTableViewCell.m
//  project
//
//  Created by 张振宇 on 15/10/28.
//  Copyright © 2015年 lanou. All rights reserved.
//

#import "commentsTableViewCell.h"
#import <UIImageView+WebCache.h>
@interface commentsTableViewCell()

@property (nonatomic,strong) UIImageView *imgView;
@property (nonatomic,strong) UILabel *nicknameLabel;
@property (nonatomic,strong) UILabel *contentLabel;
@end

@implementation commentsTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

-(void)setConfiguremodel:(StrategyCommentsModel *)configuremodel
{
    _configuremodel = configuremodel;

    
    if (![configuremodel.avatar_url isKindOfClass:[NSNull class]]) {
        [_imgView sd_setImageWithURL:[NSURL URLWithString:configuremodel.avatar_url]];
    }
    _nicknameLabel.text = configuremodel.nickname;
    if (configuremodel.replied_user_nickname == nil) {
        _contentLabel.text = configuremodel.content;
        _contentLabel.frame = CGRectMake(60, 35, kWidth - 70, [commentsTableViewCell heightforString:configuremodel.content]);
    }
    else
    {
        _contentLabel.text = [NSString stringWithFormat:@"回复%@:%@" ,configuremodel.replied_user_nickname ,configuremodel.content];
        _contentLabel.frame = CGRectMake(60, 35, kWidth - 70,[commentsTableViewCell heightforString:[NSString stringWithFormat:@"回复%@:%@",configuremodel.replied_user_nickname ,configuremodel.content]]);
    }
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _imgView = [[UIImageView alloc]initWithFrame:CGRectMake(10,10 , 40, 40)];
        _imgView.layer.cornerRadius = 20;
        _imgView.layer.masksToBounds = YES;
        //_imgView.backgroundColor = [UIColor grayColor];
        [_imgView setImage:[UIImage imageNamed:@"user_icon"]];
        [self.contentView addSubview:_imgView];
        
        _nicknameLabel = [[UILabel alloc]initWithFrame:CGRectMake(60, 10, kWidth - 70, 21)];
        [_nicknameLabel setTextColor:[UIColor blackColor]];
        [self.contentView addSubview:_nicknameLabel];
        
        _contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(60, 35, kWidth - 70, 21)];
        _contentLabel.numberOfLines = 0;
        _contentLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:_contentLabel];
    }
    return self;
}

+ (CGFloat)heightforString:(NSString *)str
{
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:14] forKey:NSFontAttributeName];
    CGRect rect = [str boundingRectWithSize:CGSizeMake(kWidth - 70, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    NSLog(@"%f",rect.size.height);
    return rect.size.height;
}

+ (CGFloat)heightforModel:(StrategyCommentsModel *)model{
    if (model.replied_user_nickname == nil) {
        return [commentsTableViewCell heightforString:model.content]+ 45;
    }
    else
    {
        return [commentsTableViewCell heightforString: [NSString stringWithFormat:@"回复%@:%@" ,model.replied_user_nickname ,model.content]]+45;
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
